package org.ran.demo.util;

public class ByteUtil {
    private ByteUtil(){}

    public static byte[] intToBytes(int input) {
        byte[] r = new byte[4];
        r[0] = (byte) (input & 0xff);
        r[1] = (byte) (input >> 8 & 0xff);
        r[2] = (byte) (input >> 16 & 0xff);
        r[3] = (byte) (input >> 24 & 0xff);
        return r;
    }

    public static int bytesToInt(byte[] input) {
        int r = 0;
        for (int i = 0; i < input.length; i++) {
            r += (input[i] & 0xff) << (i*8);
        }
        return r;
    }
}
